package com.itheima.stream;

import com.itheima.domain.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/*
流的收集方法
 */
public class Demo04 {
    public static void main(String[] args) {
        Student cai = new Student("蔡徐坤", 16);
        Student wu = new Student("吴亦凡", 31);
        Student tu = new Student("小土豆", 15);
        Student zhou = new Student("周杰伦", 40);
        ArrayList<Student> list = new ArrayList<>(List.of(cai,cai, wu, tu, zhou));
        //想要 年龄在18一下的人的集合
       /* ArrayList<Student> newList = new ArrayList<>();
        for (Student student : list) {
            if(student.getAge()<=18){
                newList.add(student);
            }
        }
        newList.forEach(s-> System.out.println(s));
*/
       //需要一个Collector  Collectors
        /*List<Student> collect = list.stream()
                .filter(s -> s.getAge() <= 18)
                .collect(Collectors.toList());
        for (Student student : collect) {
            System.out.println(student);
        }
    */
        Set<Student> collect = list.stream()
                .filter(s -> s.getAge() <= 18)
                .collect(Collectors.toSet());
        for (Student student : collect) {
            System.out.println(student);
        }
    }




}
